package org.slg.oracleproject.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slg.oracleproject.respones.CommonResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.slg.oracleproject.entity.RolePermission;
import org.slg.oracleproject.service.RolePermissionService;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;

/**
 *  控制层。
 *
 * @author 沙龙果
 * @since 2025年09月23日
 */
@RestController
@RequestMapping("/rolePermission")
@Tag(name = "角色权限模块",description = "暂未开发")
public class RolePermissionController {

    @Autowired
    private RolePermissionService rolePermissionService;

    /**
     * 添加。
     *
     * @param rolePermission 
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    @Operation(summary = "添加")
    public CommonResult save(@RequestBody RolePermission rolePermission) {
        return CommonResult.success(rolePermissionService.save(rolePermission));
    }

    /**
     * 根据主键删除。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @GetMapping("remove/{id}")
    @Operation(summary = "根据主键删除")
    public CommonResult remove(@PathVariable Serializable id) {
        return  CommonResult.success(rolePermissionService.removeById(id));
    }

    /**
     * 根据主键更新。
     *
     * @param rolePermission 
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @GetMapping("update")
    @Operation(summary = "根据主键更新")
    public CommonResult update(@RequestBody RolePermission rolePermission) {
        return CommonResult.success(rolePermissionService.updateById(rolePermission));
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(summary = "查询所有")
    public CommonResult list() {
        return CommonResult.success(rolePermissionService.list());
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(summary = "根据主键获取详细信息")
    public CommonResult getInfo(@PathVariable Serializable id) {
        return CommonResult.success(rolePermissionService.getById(id));
    }

}
